package com.dragon.common.modules.uaa.web.controller;

import com.chris.dev.base.libs.v1.http.params.NoneParam;
import com.chris.dev.base.libs.v1.http.results.CodeResult;
import com.chris.dev.base.libs.v1.http.results.ValueResult;
import com.dragon.common.modules.uaa.service.def.AuthAccountService;
import com.dragon.common.modules.uaa.web.api.AuthAccountApi;
import com.dragon.common.modules.uaa.web.models.params.*;
import com.dragon.common.modules.uaa.web.models.results.LoginResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Chris Chan
 * Create On 2025/7/18 下午11:13
 * Use for: 认证-账号相关接口
 * Explain: 认证-账号相关接口均无需认证，直接调用即可
 */
@RestController
@RequestMapping("auth/account")
public class AuthAccountController implements AuthAccountApi {
    @Autowired
    AuthAccountService authAccountService;

    @Override
    public CodeResult<String> getGraphVerifyCode(@RequestBody NoneParam param) {
        return CodeResult.of(authAccountService.getGraphVerifyCode());
    }


    @Override
    public ValueResult<Boolean> sendMobileVerifyCode(@RequestBody @Valid MobileParam param) {
        return ValueResult.of(authAccountService.sendMobileVerifyCode(param.getMobile()));
    }

    @Override
    public ValueResult<Boolean> sendEmailVerifyCode(@RequestBody @Valid EmailParam param) {
        return ValueResult.of(authAccountService.sendEmailVerifyCode(param.getEmail()));
    }

    @Override
    public ValueResult<Boolean> registerByUsernamePassword(@RequestBody @Valid RegisterByUsernamePasswordParam param) {
        return ValueResult.of(authAccountService.registerByUsernamePassword(
                param.getUsername(), param.getPassword(), param.getConfirmPassword(),
                param.getVerifyCode()));
    }

    @Override
    public ValueResult<Boolean> registerByMobileVerifyCode(@RequestBody @Valid RegisterByMobileVerifyCodeParam param) {
        return ValueResult.of(authAccountService.registerByMobileVerifyCode(param.getMobile(), param.getVerifyCode()));
    }

    @Override
    public ValueResult<Boolean> registerByEmailVerifyCode(@RequestBody @Valid RegisterByEmailVerifyCodeParam param) {
        return ValueResult.of(authAccountService.registerByEmailVerifyCode(param.getEmail(), param.getVerifyCode()));
    }

    @Override
    public LoginResult loginByUsernamePassword(@RequestBody @Valid LoginByUsernamePasswordParam param) {
        return authAccountService.loginByUsernameAndPassword(param.getUsername(), param.getPassword());
    }

    @Override
    public LoginResult loginByMobileVerifyCode(@RequestBody @Valid LoginByMobileVerifyCodeParam param) {
        return authAccountService.loginByMobileVerifyCode(
                param.getMobile(), param.getVerifyCode());
    }

    @Override
    public LoginResult loginByEmailVerifyCode(@RequestBody @Valid LoginByEmailVerifyCodeParam param) {
        return authAccountService.loginByEmailVerifyCode(
                param.getEmail(), param.getVerifyCode());
    }

    @Override
    public ValueResult<Boolean> resetPasswordByMobile(@RequestBody @Valid ResetPasswordByMobileParam param) {
        return ValueResult.of(authAccountService.resetPasswordByMobile(param.getMobile(), param.getVerifyCode()));
    }

    @Override
    public ValueResult<Boolean> resetPasswordByEmail(@RequestBody @Valid ResetPasswordByEmailParam param) {
        return ValueResult.of(authAccountService.resetPasswordByEmail(param.getEmail(), param.getVerifyCode()));
    }

    @Override
    public LoginResult refreshLoginResult(@RequestBody @Valid TokenParam param) {
        return authAccountService.refreshLoginResult(param.getToken());
    }

    @Override
    public ValueResult<Boolean> activateAccount(@RequestParam("code") String code) {
        return ValueResult.of(authAccountService.activateAccount(code));
    }

}
